﻿using System;
using System.Collections.Generic;

namespace Framework
{
    public class UIClickListener
    {
        private Action<object[]> _callback;
        private object[] _args;
        private readonly List<object> _listArg = new List<object>(20);

        public UIClickListener(Action<object[]> callback, object[] args)
        {
            _callback = callback;
            _args = args;
        }

        public void Invoke()
        {
            PushArgs();
            _callback.Invoke(_listArg.ToArray());
        }
        

        public void Invoke<T1>(T1 arg)
        {
            PushArgs();
            _listArg.Add(arg);
            _callback.Invoke(_listArg.ToArray());
        }
        
        private void PushArgs()
        {
            _listArg.Clear();
            if (_args != null)
            {
                _listArg.AddRange(_args);
            }
        }

        public bool Equals(Action<object[]> callback)
        {
            return _callback == callback;
        }
    }
}